package com.mmall.concurrency.singleton;

import com.mmall.concurrency.annotations.Recommend;
import com.mmall.concurrency.annotations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

/**
 * m枚举模式最安全
 */
@Slf4j
@ThreadSafe
@Recommend
public class Singleton7 {

    private Singleton7(){

    }

    public static Singleton7 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton{
        INSTANCE;

        private Singleton7 singleton;

        //jvm 保证绝对值调用一次
        Singleton(){
            singleton = new Singleton7();
        }

        public Singleton7 getInstance(){
            return singleton;
        }
    }
}
